#!/usr/bin/env python3

import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt

img = cv.imread('../pic/7.png', 1)

# # filter2D
# # 卷积核大小5*5 矩阵全是1 矩阵取平均故/25
# kernel = np.ones((5, 5), np.float32) / 25
# # 图像模糊处理
# dst = cv.filter2D(img, -1, kernel)

# # 均值滤波
blur = cv.blur(img, (5, 5))

# 高斯滤波 噪点减少，模糊程度少于均值滤波
gauss_blur = cv.GaussianBlur(img, (5, 5), 0)

# 中位模糊 确实能减少椒盐噪声，但是图像模糊程度变大
median_blur = cv.medianBlur(img, 5)

# 双边滤波 噪点减少，边缘保留 sigma没搞懂
bil_blur = cv.bilateralFilter(img, 9, 75, 75)

plt.figure(figsize=(15, 15))
plt.subplot(131), plt.imshow(cv.cvtColor(img, cv.COLOR_BGR2RGB)), plt.title('Original')
plt.xticks([]), plt.yticks([])
plt.subplot(132), plt.imshow(cv.cvtColor(gauss_blur, cv.COLOR_BGR2RGB)), plt.title('gauss_blur')
plt.xticks([]), plt.yticks([])
plt.subplot(133), plt.imshow(cv.cvtColor(bil_blur, cv.COLOR_BGR2RGB)), plt.title('bil_blur')
plt.xticks([]), plt.yticks([])
plt.show()






